/**
 * Created by Administrator on 2017/3/10.
 */

var timeFormat = module.exports;
timeFormat.randomString = function(len) {
    len = len || 32;
    var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
    var maxPos = $chars.length;
    var pwd = '';
    for (i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
    }
    return pwd;
};

//格林威治时间转换
timeFormat.handle = function (data) {
    if(data.created_date != undefined) {
        data.created_date = format_time(data.created_date);
    }

    if(data.updated_date != undefined) {
        data.updated_date = format_time(data.updated_date);
    }
    return data;
}

function format_time(str) {
   if(str.indexOf('.000Z') >= 0) {
       str = str.replace(/T/,' ');
       str = str.replace(/.000Z/,' ');
       var a1;
       var a2;
       a1 = str.split(' ');
       a2 = a1[1].split(':');
       a2[0] =parseInt(a2[0]) + 8;
       if(a2[0] >= 24) {
           a1[0] = a1[0].split('-');
           a1[0][2] = parseInt(a1[0][2]) + 1;
           a1[0] = a1[0].join('-');
           a2[0] = a2[0]-24;
           if(a2[0] < 10) {
               a2[0] = '0'+a2[0];
           }
       }
       a2 = a2.join(':');
       var update_time = a1[0]+' '+a2;
       return update_time;
   } else {
       return  str;
   }
}